package com.baizhi.springbootday0202.controller;

import com.baizhi.springbootday0202.entity.User;
import com.baizhi.springbootday0202.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
	@Autowired
	private UserService userService;

	/**
	 *
	 * @param name  接收账号
	 * @param pwd    接收密码
	 * @return 返回跳转的地址
	 */
	@RequestMapping("/login")
	public String  login(String name, String pwd, HttpSession session){
		User user = userService.selectUser(name, pwd);
		if(user != null){
			session.setAttribute("user",user);
			return "auction";
		}else{
			return "login";
		}
	}


	@RequestMapping("/register")
	public String  register(User user){
		userService.insertUser(user);
		return "login";
	}
}
